FROM golang:1.16-alpine AS build
RUN apk add --no-cache git && apk add gcc musl-dev
COPY . /go/src/httpserver/
WORKDIR /go/src/httpserver/
RUN go env -w GO111MODULE=on && go env -w GOPROXY="https://goproxy.cn,direct" && CGO_ENABLED=0 go build -a -ldflags='-extldflags "-static"' -o /bin/httpserver ./httpserver.go

FROM scratch
COPY --from=build /bin/httpserver /bin/server
EXPOSE 9000
ENTRYPOINT ["/bin/server"]